<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>编辑</title>
    <style>
        .container .kc {
            background-color: #f5f5f5;
        }

        /* .card.col-md-4.ms-3.mt-3:hover{
            background: rgb(241, 240, 240);
        }
        .card.col-md-4.ms-3.mt-3 .mt-1.text-muted:hover,.card.col-md-4.ms-3.mt-3 .card-title:hover{
            color: rgb(97, 172, 172) !important;
        } */
        .link-secondary:hover {
            color: #0d6efd !important;
        }

        .leftmenu {
            min-height: 100vh;
        }
    </style>
</head>

<body>
    <div class="container bg-body-secondary">
        <div class="row">
            <div class="col-md-2 leftmenu" id="leftmenu"></div>
            <div class="col-md-9 col-xs-12 kc ms">
                <div class="row mt-3 pb-1 border-bottom border-secondary">
                    <div class="col-md-2">编辑学生</div>
                </div>

                <div class="row mt-3">
                    <form class="col-md-5" id="studentForm">
                        <!-- 手机号 -->
                        <div class="mb-3">
                            <label for="tel" class="form-label">手机:</label>
                            <input name="tel" type="tel" required class="form-control" id="tel" aria-describedby="tel"
                                placeholder="请输入手机号">
                        </div>
                        <!-- 学号 -->
                        <div class="mb-3">
                            <label for="sno" class="form-label">学号:</label>
                            <input name="sno" type="number" required class="form-control" id="sno"
                                aria-describedby="tel" placeholder="请输入学号">
                        </div>
                        <!-- 姓名 -->
                        <div class="mb-3">
                            <label for="name" class="form-label">姓名:</label>
                            <input name="name" type="name" required class="form-control" id="name"
                                aria-describedby="tel" placeholder="请输入姓名">
                        </div>
                        <div class="mb-3">
                            <button type="button" class="btn btn-success">保存</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    </div>
</body>
<script type="module" src="../js/main.js"></script>
<script src="../js/jquery.min.js"></script>
<script src="../js/common.js"></script>
<script>
    function getUrlParams(key) {// 获取网址中参数信息"key"中放属性名
        var url = window.location.search.substr(1);
        if (url == '') {
            return false;
        }
        var paramsArr = url.split('&');
        for (var i = 0; i < paramsArr.length; i++) {
            var combina = paramsArr[i].split("=");
            if (combina[0] == key) {
                return combina[1];
            }
        }
        return false;
    }
    //console.log(getUrlParams("id"));
    //获取将要编辑的数据信息 在页面显示
    //遇到问题 不知道怎么获取页面网址上的id值
    $.get(`http://unicloud.codecore.cn/ms/getStudent?id=${getUrlParams("id")}`, {}, function (params) {
         if (params.errCode == 0) {
             $("#tel").val(params.data.tel)
             $("#name").val(params.data.student_name)
             $("#sno").val(params.data.sno)

         }
        console.log(params);
    })
    //点击保存更新数据
    $(".btn-success").click(function(){
        $.post("http://unicloud.codecore.cn/ms/studentUpdate",{
            id:getUrlParams("id"),
            tel:$("#tel").val(),
            student_name:$("#name").val(),
            sno:$("#sno").val(),
        },function (params) {
            if(params.errCode == 0){//更新成功跳转回去
                history.back()
            }else{
                alert("更新失败")
            }
            
        })
    })
</script>

</html>